(function() {
  var __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  this.AdminBookCreateView = (function(_super) {

    __extends(AdminBookCreateView, _super);

    function AdminBookCreateView() {
      return AdminBookCreateView.__super__.constructor.apply(this, arguments);
    }

    AdminBookCreateView.prototype.el = $('#content');

    AdminBookCreateView.prototype.initialize = function() {
      return AdminBookCreateView.__super__.initialize.apply(this, arguments);
    };

    AdminBookCreateView.prototype.render = function() {
      var el, model;
      model = this.model;
      el = $(this.el);
      return this.GetTemplate(SiteMap.Admin.Books.CreateTemplate, function(compiledTemplate) {
        el.html(compiledTemplate(model.toJSON()));
        $("#UserId").combobox({
          source: SiteMap.Admin.Shared.GetUsers,
          isDynamic: true
        });
        $("#Authors").combobox({
          isMulti: true,
          isDynamic: true,
          source: SiteMap.Admin.Shared.GetAuthors
        });
        $("#Categories").combobox({
          isMulti: true,
          isDynamic: true,
          source: SiteMap.Admin.Shared.GetCategories
        });
        $("#DateOfPublish").datepicker();
        $("#Avatar").ImageUpload();
        return $("#FileName").FileUploader();
      });
    };

    AdminBookCreateView.prototype.events = {
      "click .buttons>button.save": "save",
      "click .buttons>button.cancel": "cancel"
    };

    AdminBookCreateView.prototype.save = function(e) {
      var data,
        _this = this;
      e.preventDefault();
      if (!this.IsValid()) {
        Messages.Clear();
        Messages.WriteMessage('Please, correct errors.');
        return;
      }
      Loading.Start();
      Messages.WriteMessage('Creating book.');
      data = $(this.el).find("form.general").serialize();
      return $.ajax({
        url: SiteMap.Admin.Books.Create,
        type: 'POST',
        data: data,
        success: function(response) {
          if ((response.SuccessMessage != null) && response.SuccessMessage.length) {
            Messages.WriteSuccessMessage(response.SuccessMessage);
            return _this.Navigate(SiteMap.Admin.Books.Listing, true);
          } else {
            Messages.WriteErrors(response.Errors);
            return Loading.Stop();
          }
        }
      });
    };

    AdminBookCreateView.prototype.cancel = function(e) {
      e.preventDefault();
      Loading.Start();
      Messages.Clear();
      return this.Navigate(SiteMap.Admin.Books.Listing, true);
    };

    return AdminBookCreateView;

  })(CustomView);

}).call(this);
